@extends('public.base')
@section('body')

    <div class="layui-row">
        <form id="main_form" class="layui-form layui-form-pane" action="" method="post" lay-filter="main-form-group">
            <!-- ==================================  隐藏区  ================================== -->
            <!--隐藏域-->

            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-tab-item layui-show">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">帐号</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="username" value="{{$data["username"]}}"
                                           lay-verify="required" lay-verType="tips"
                                           autocomplete="off"
                                           class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">用户登陆的帐号</div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">用户名</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="nickname" value="{{$data["nickname"]}}"
                                           lay-verify="required" lay-verType="tips"
                                           autocomplete="off"
                                           class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">户登陆的昵称</div>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">修改密码</label>
                            <div class="layui-input-inline">
                                <input type="password" name="password"  lay-verType="tips" autocomplete="off" id="LAY_password" class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">如果不修改密码请留空</div>
                        </div>


                        <div class="layui-form-item">
                            <label class="layui-form-label">用户头像</label>
                            <div class="layui-input-inline">
                                <input type="text" id="upload_img_url" name="logo" autocomplete="off"
                                       placeholder="请输入标题"
                                       class="layui-input" readonly value="{{$data["logo"]}}">
                            </div>
                            <div class="layui-input-inline layui-btn-container" style="width: auto;">
                                &nbsp;<button type="button" class="layui-btn layui-btn-primary" id="upload_img_btn"><i
                                            class="layui-icon">&#xe67c;</i>上传图片
                                </button>
                                <button type="button" class="layui-btn layui-btn-primary" id="upload_img_preview"  onclick="show_one_pic(document.getElementById('upload_img_url').value)">预览图片
                                </button>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">性别</label>
                                <div class="layui-input-inline">
                                    <input type="checkbox" id="select_upload_type" name="sex" {{$data["sex"]==1?'checked':''}} lay-skin="switch"
                                           lay-filter="component-form-switchuploadtype" lay-text="男|女">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">联系手机号</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="mobile" lay-verify="required|phone" lay-verType="tips" autocomplete="off"
                                           placeholder="请输入参数名称"
                                           class="layui-input" value="{{$data["mobile"]}}">
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">生日</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" id="birthday" name="birthday"
                                       lay-verify="required" lay-verType="tips"
                                       autocomplete="off"
                                       format="date" placeholder="开始时间" value="{{$data["birthday"]}}">
                            </div>
                            <div class="layui-form-mid layui-word-aux"></div>
                        </div>


                    </div>
                </div>
            </div>
            <input type="hidden" name="id" value="{{$data["id"]}}"/>
            <!-- 按钮区 -->
            <div class="layui-form-item layui-layout-admin" style="display: none">
                <div class="layui-input-block">

                    <div class="layui-footer" style="left: 0;">
                        <button id="form_save" lay-filter="form_save" class="layui-btn"
                                lay-submit="">
                            保存
                        </button>
                        <button id="form_reset" type="button" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </div>
        </form>
    </div>


    <script src="{{ADMIN_PATH}}layui/layuiadmin/layui/layui.js"></script>
    <script src="{{ADMIN_PATH}}js/admin.common.js"></script>
    <script>

        var save_url = '{{url('admin/member/edit')}}';
        layui.config({
            base: '{{ADMIN_PATH}}layui/layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form', 'laydate'], function(){
            var $ = layui.$
                ,admin = layui.admin
                ,element = layui.element
                ,layer = layui.layer
                ,laydate = layui.laydate
                ,form = layui.form;

            form.render(null, 'component-form-group');

            laydate.render({
                elem: '#LAY-component-form-group-date'
            });

            /* 自定义验证规则 */
            form.verify({
                title: function(value){
                    if(value.length < 5){
                        return '标题至少得5个字符啊';
                    }
                }
                ,pass: [/(.+){6,12}$/, '密码必须6到12位']
                ,content: function(value){
                    layedit.sync(editIndex);
                }
            });

            /* 监听指定开关 */
            form.on('switch(component-form-switchTest)', function(data){
                layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
                    offset: '6px'
                });
                layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
            });

            /* 监听提交 */
            form.on('submit(form_save)', function(data){
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                $.post(save_url, data.field, function (res) {
                    try {
                        if(res.status==200) {
                            //重新刷新父窗口的数据区
                            parent.layui.table.reload('test-table-reload'); //重载表格
                            parent.layer.close(index); //再执行关闭
                        }else{
                            layer.msg(res.message);
                        }
                    } catch (e) {
                        layer.msg("异常");
                    }

                }, "json");

                return false;
            });
        });

        layui.use('upload', function(){
            var upload = layui.upload;
            upload.render({
                elem: '#upload_img_btn'
                ,url: '/public/upload/pic' //上传接口
                ,done: function(res, index, upload){
                    //获取当前触发上传的元素，一般用于 elem 绑定 class 的情况，注意：此乃 layui 2.1.0 新增
                    var item = this.item;
                    if (res.code == 0) {
                        item.closest(".layui-form-item").find("#upload_img_url").val(res.data.src);
                    } else {
                        layer.msg(res.message);
                    }
                }
            });
        });

        //=============================================时间选框================================================
        layui.use('laydate', function () {
            var laydate = layui.laydate;

            //开始日期
            var insStart = laydate.render({
                elem: '#birthday'
                , type: 'date'
                //, min: 0
                , done: function (value, date) {
                    //更新结束日期的最小日期

                }
            });


        });
    </script>
@stop